from django.test import TestCase

import os, json
from string import Template
# Create your tests here.

# print(os.path.exists("E:\\bilibiliTool\\djangoProject\\resource\\userInfo.json"))
# with open("E:\\bilibiliTool\\djangoProject\\resource\\userInfo.json", 'w') as file:
#     file.write('{"mid": 0, "name": "", "face": "", "follower": 0}')
# with open("E:\\bilibiliTool\\djangoProject\\resource\\userInfo.json", 'r') as file:
#     print(json.dumps(file.read()))


from bilibili_api import comment, sync

async def main():
    # 存储评论
    comments = []
    # 页码
    page = 1
    # 当前已获取数量
    count = 0
    while True:
        # 获取评论
        c = await comment.get_comments(692747743468191812, comment.ResourceType.DYNAMIC_DRAW, page)
        # 存储评论
        comments.extend(c['replies'])
        # 增加已获取数量
        count += c['page']['size']
        # 增加页码
        page += 1

        if count >= c['page']['count']:
            # 当前已获取数量已达到评论总数，跳出循环
            break

    # 打印评论
    for cmt in comments:
        print(f"{cmt['member']['uname']}: {cmt['content']['message']}")

    # 打印评论总数
    print(f"\n\n共有 {count} 条评论（不含子评论）")


sync(main())
